!pr2
Finding the Erroneous Bit Using CRC.................Bruce Love
                                         Hamilton, New Zealand

The April 1984 AAL article about using Cyclic Redundancy Codes posed the question, "How do you find out which bit was in error, assuming only one was wrong?"  I found a way.

My algorithm assumes that there was one and only one bit wrong in the entire 258-byte message (256 bytes of original message plus 2 bytes of CRC).  The bits are numbered left-to-right, or most significant bit of first byte received through the least significant bit of the CRC, 0 through $80F (or 2063, if you prefer decimal).

After receiving the data and CRC, the RECV program has computed a composite CRC and the result will be $0000 if there were no errors.  If the result is non-zero, it uniquely determines which bit was wrong.  Here is a summary of my algorithm for finding which bit:

       let bit.number = 2063
       let dummy.crc  = 1
    -->if dummy.crc = crc, then we found the bit
   |   decrement bit.number
   |   shift dummy.crc left 1 bit
   |   if carry set, EOR with $1021
    ---loop

[ The following comments are by Bob Sander-Cederlof. ]

The program listing which follows is an addendum to the listing in the April issue of AAL.  Lines 3070 through the end should be appended to the program in that issue.  If you buy the AAL Quarterly Disk, it will already be there.

The sequence I used for testing the program went like this.  First I assembled the whole program, April's plus the one below.  Then I typed "$4000<F800.F8FFM" to move a copy of the monitor's first page into the test buffer.  I thought this would be "interesting" data to play with.  Then these steps:

       :MGO SEND       (fakes sending the buffer)
       1F45            (SEND prints out the CRC for BUFFER)
       :$4000          (see what is there)
       4A              (it was $4A)
       :$4000:CA       (make a fake error in the 1st bit)
       :MGO RECV
       xxxx            (some non-zero value)
       :MGO FIND.BAD.BIT
       0000            (the bad bit was the first bit)
       $4000:4A        (restore the correct bit

Then I tried the same steps on various other bit positions, with accurate results in every case.
